package com.fhz.day0006;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.fhz.day0006.fragment.FourFragment;
import com.fhz.day0006.fragment.MyFragmentAdapter;
import com.fhz.day0006.fragment.OneFragment;
import com.fhz.day0006.fragment.ThreeFragment;
import com.fhz.day0006.fragment.TwoFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager vp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        vp = (ViewPager) findViewById(R.id.vp);


        //不用fragment的vp
//        extracted();


        List<Fragment> list = new ArrayList<>();

        list.add(new OneFragment());
        list.add(new TwoFragment());
        list.add(new ThreeFragment());
        list.add(new FourFragment());

        //使用fragment填充的vp
        vp.setAdapter(new MyFragmentAdapter(getSupportFragmentManager(),list));
    }

    //ctrl+alt +m
    private void extracted() {
        List<String> list = new ArrayList<>();

        list.add("第一页");
        list.add("第二页");
        list.add("第三页");

        vp.setAdapter(new MyAdapter(list,this));
    }
}